package com.dh.core.util;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.dh.core.config.Constant;

import java.io.ByteArrayInputStream;


/**
 * @author hong.li
 * @Title: OssUploadUtils
 * @Description: OSS上传工具类
 * @date 16/7/4 上午12:56
 */
public class OssUploadUtils {
    private static OSSClient client =
        new OSSClient(Constant.OSS_ENDPOINT, Constant.OSS_ACCESS_ID, Constant.OSS_ACCESS_KEY);



    /**
     * 上传文件到oss
     * @param data
     * @param type
     * @param key
     */
    public static void uploadFile(byte[] data, String type, String key) {
        ObjectMetadata objectMeta = new ObjectMetadata();
        objectMeta.setContentLength(data.length);
        objectMeta.setContentType(type);
        objectMeta.setCacheControl("max-age=604800");
        objectMeta.setContentDisposition("inline");
        client.putObject(Constant.BUCKET_NAME, key, new ByteArrayInputStream(data), objectMeta);
    }



}
